package bhbt.controller.admin.ti;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import bhbt.controller.core.BaseController;
import bhbt.model.log.LogMoneyTi;
import bhbt.service.log.LogMoneyTiService;
import bhbt.utils.MapUtil;





/**
 * Created by Administrator on 2016/3/25.
 */
@Controller
 
public class MoneyTiShowController extends BaseController {
	@Resource
    private LogMoneyTiService logMoneyTiService;
   
   

    @RequestMapping("admin/ti/moneyTiShow.shtml")
    public String show(HttpServletRequest request) throws Exception{
        Map formMap = getParameterMap(request);
        int id = MapUtil.getIntValue(formMap, "id");
        if(0 < id){
        	
        	 
        	//方法二
        	formMap.put("id", id);	//未激活
        	List<LogMoneyTi> list = logMoneyTiService.queryForList("logMoneyTiForList",formMap);
        	
        	if(list.size()>0){
        		System.out.println("list.get(0):"+list.get(0));
            	//member=list.get(0);
            	request.setAttribute("logMoneyTi", list.get(0));
        	}
        	
        }
        return "admin/ti/moneyTiShow";
       
    }
     
    
    @RequestMapping("admin/ti/moneyTiCommit.shtml")
    public String commit(HttpServletRequest request, ModelMap model) throws Exception{
        Map formMap = getParameterMap(request);
        int id = MapUtil.getIntValue(formMap, "id");
        String caifuNo =new String(MapUtil.getString(formMap,"caifuNo").getBytes("iso-8859-1"),"utf-8");
        if(0 < id){
        	Map mapLogMoneyTi = new HashMap();
        	mapLogMoneyTi.put("id",id);
        	mapLogMoneyTi.put("state",20);
        	mapLogMoneyTi.put("commitDate",new Date());
        	mapLogMoneyTi.put("caifuNo",caifuNo);
        	
        	logMoneyTiService.update(mapLogMoneyTi);
        	
        	setMessage(model,"审核成功！");
        	
        	formMap.put("id", id);	//未激活
        	List<LogMoneyTi> list = logMoneyTiService.queryForList("logMoneyTiForList",formMap);
        	
        	if(list.size()>0){
        		System.out.println("list.get(0):"+list.get(0));
            	//member=list.get(0);
            	request.setAttribute("logMoneyTi", list.get(0));
        	}
        }
        return "redirect:moneyTiList.shtml";
         
       
    }
    
    
    @RequestMapping("admin/ti/moneyTiCancel.shtml")
    public String cancel(HttpServletRequest request, ModelMap model) throws Exception{
        Map formMap = getParameterMap(request);
        int id = MapUtil.getIntValue(formMap, "id");
        
        String caifuNo =new String(MapUtil.getString(formMap,"caifuNo").getBytes("iso-8859-1"),"utf-8");
        if(0 < id){
        	
        	logMoneyTiService.updateCancel(id,caifuNo);
        	setMessage(model,"审核成功！");
        	
        	formMap.put("id", id);	//未激活
        	List<LogMoneyTi> list = logMoneyTiService.queryForList("logMoneyTiForList",formMap);
        	
        	if(list.size()>0){
        		System.out.println("list.get(0):"+list.get(0));
            	//member=list.get(0);
            	request.setAttribute("logMoneyTi", list.get(0));
        	}
        }
        return "admin/ti/moneyTiShow";
       
    }

}
